//
//  RootController.m
//  MyIOSTools
//
//  Created by chenxin on 12-12-1.
//  Copyright (c) 2012年 xin chen. All rights reserved.
//

#import "RootController.h"
#import "RootTableCellController.h"
#import "TestViewController.h"
@interface RootController ()

@end

@implementation RootController
@synthesize table=_table;
@synthesize array=_array;
- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSMutableArray *arrayOfController=[NSMutableArray arrayWithObjects:@"cx",@"cxx", nil];
    self.array=arrayOfController;
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
 
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [self.array count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *rootCell = @"rootCell";//此处名字要与布局中的identifier属性填写一直
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    
    RootTableCellController *cell = (RootTableCellController *)[tableView
                                      dequeueReusableCellWithIdentifier:rootCell];
    //取消选中颜色
//    UIView *backView = [[UIView alloc] initWithFrame:cell.frame];
//    cell.selectedBackgroundView = backView;
//    cell.selectedBackgroundView.backgroundColor = [UIColor clearColor];
    
    //取消边框线
//    [cell setBackgroundView:[[UIView alloc] init]];          //取消边框线
//    cell.backgroundColor = [UIColor clearColor];
    
    
    // Configure the cell...
    NSInteger row=[indexPath row];
    cell.lab_name.text=[self.array objectAtIndex:row];
    
    
    return cell;
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    /*
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     [detailViewController release];
     */
    NSInteger row=[indexPath row];
    UIStoryboard * storyboard = [ UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil ];   
//    UIViewController *selectedController;
    if(row==0){
        TestViewController *testController=[storyboard instantiateViewControllerWithIdentifier:@"TestViewController"];//此处写与identifier相同
        
        
//        selectedController=testController;
        [self.navigationController pushViewController:testController animated:YES];
        
    }
//    if(selectedController!=nil){
//        [self.navigationController pushViewController:selectedController animated:YES];}
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (void)dealloc {
    [_array release];
    [_table release];
    [super dealloc];
}
- (void)viewDidUnload {
    [self setArray:nil];
    [self setTable:nil];
    [super viewDidUnload];
}
@end
